package com.wjj.sixinone.controller.admin;


import com.wjj.sixinone.common.enums.ApiTypeConst;
import com.wjj.sixinone.common.pojo.dto.ChartDataDTO;
import com.wjj.sixinone.common.util.Result;
import com.wjj.sixinone.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping(ApiTypeConst.API_ADMIN + "/index")

public class IndexController {
    @Autowired
    private IndexService indexService;

    @GetMapping("/dashboard")
    public Result dashboard() {
        return indexService.dashboard();
    }

    @GetMapping("/getLineChartData")
    public Result getLineChartData() {
        return indexService.getLineChartData();
    }

    @GetMapping("/getPieChartData")
    public Result getPieChartData() {
        return indexService.getPieChartData();
    }


    @GetMapping("/chartData")
    public ChartDataDTO getChartData() {
        ChartDataDTO chartDataDTO = new ChartDataDTO();

        // 模拟生成数据
        List<String> categories = new ArrayList<>();
        List<Integer> categories2 = new ArrayList<>();
        List<Integer> data = new ArrayList<>();
        List<Integer> data2 = new ArrayList<>();
        Random random = new Random();

        for (int i = 0; i < 10; i++) {
            categories.add(new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date(System.currentTimeMillis() - 2000 * (9 - i))));
            categories2.add(i);
            data.add(random.nextInt(201) + 800);
            data2.add(random.nextInt(11) + 5);
        }

        chartDataDTO.setCategories(categories);
        chartDataDTO.setCategories2(categories2);
        chartDataDTO.setData(data);
        chartDataDTO.setData2(data2);

        return chartDataDTO;
    }

}
